<?php

namespace Liuhelong\LaravelAdmin\Wechat\Http\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Liuhelong\LaravelAdmin\Wechat\Models\WechatOffiaccountMpNewsArticle;
use Encore\Admin\Admin;
use Request;
use Log;
use Liuhelong\LaravelAdmin\Wechat\Common;

class WechatOffiaccountMpNewsArticleController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '图文消息';
    protected $description = [
        'index'  => '公众号中需要先进行发布，这里才可以使用，用于客服消息 自动回复等',
        //        'show'   => 'Show',
        //        'edit'   => 'Edit',
        //        'create' => 'Create',
    ];

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new WechatOffiaccountMpNewsArticle());

        $grid->column('article_id',__('laravel_admin_wechat.Media id'))->copyable();
		
		$grid->column('content', __('laravel_admin_wechat.Content'))->display(function($content,$column){
            
            return Common::showNews($content);
        });
        $grid->column('update_time',__('laravel_admin_wechat.Updated at'));
        
        $grid->column('tags', __('laravel_admin_wechat.Tag'))->display(function($tags){
			$str = '';
			if(empty($tags))
			    return '';
			    
			foreach($tags as $tag){
				$str .= '<span class="label label-primary"  style="margin:3px;display:inline-block;padding:4px;">'.$tag.'</span><br>';
			}
			return $str;
		})->hide();

		$grid->disableFilter(false);
		$grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();
        
			
        });
		$grid->disableActions();
		
		$grid->header(function ($query) {
        
            return '<meta name="referrer" content="never">';
        });
		Admin::style('.table {font-size: 14px;}');
		
        return $grid;
    }


    
}
